package work.droit.gui.swing;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import work.droit.gui.ApiController;
import org.eclipse.wb.swt.SWTResourceManager;
import org.eclipse.wb.swt.layout.grouplayout.GroupLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

public class ConfigurationFrame extends Shell
{

	/**
	 * Launch the application.
	 * 
	 * @param args
	 */
	public static void main(String args[])
	{
		try
		{
			Display display = Display.getDefault();
			ConfigurationFrame shell = new ConfigurationFrame(display);
			shell.open();
			shell.layout();
			while (!shell.isDisposed())
			{
				if (!display.readAndDispatch())
				{
					display.sleep();
				}
			}
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}
	
	public void launch()
	{
		Display display = getDisplay();
		this.open();
		this.layout();
		while (!this.isDisposed())
		{
			if (!display.readAndDispatch())
			{
				display.sleep();
			}
		}
	}

	/**
	 * Create the shell.
	 * 
	 * @param display
	 */
	public ConfigurationFrame(final Display display)
	{
		super(display, SWT.SHELL_TRIM);
		setImage(SWTResourceManager.getImage(ConfigurationFrame.class, "/work/droit/rc/images/settings_16.png"));

		Button btnFiche = new Button(this, SWT.NONE);
		btnFiche.addSelectionListener(new SelectionAdapter()
		{
			@Override
			public void widgetSelected(SelectionEvent e)
			{
				EditFichesFrame editFichesFrame = new EditFichesFrame(display);
				editFichesFrame.launch();
			}
		});
		btnFiche.setImage(SWTResourceManager.getImage(ConfigurationFrame.class,
				"/work/droit/rc/images/document_pencil_64.png"));
		btnFiche.setText("Fiches");

		Button btnDefinition = new Button(this, SWT.NONE);
		btnDefinition.addSelectionListener(new SelectionAdapter()
		{
			@Override
			public void widgetSelected(SelectionEvent arg0)
			{
				EditDefinitionsFrame editDefinitionsFrame = new EditDefinitionsFrame(display);
				editDefinitionsFrame.launch();
			}
		});
		btnDefinition.setImage(SWTResourceManager.getImage(ConfigurationFrame.class,
				"/work/droit/rc/images/network_pencil_64.png"));
		btnDefinition.setText("D\u00E9finitions");
		GroupLayout groupLayout = new GroupLayout(this);
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(GroupLayout.LEADING)
				.add(groupLayout.createSequentialGroup()
					.addContainerGap()
					.add(btnFiche, GroupLayout.DEFAULT_SIZE, 158, Short.MAX_VALUE)
					.add(194)
					.add(btnDefinition, GroupLayout.DEFAULT_SIZE, 158, Short.MAX_VALUE)
					.add(14))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(GroupLayout.LEADING)
				.add(groupLayout.createSequentialGroup()
					.addContainerGap()
					.add(groupLayout.createParallelGroup(GroupLayout.LEADING)
						.add(btnDefinition, GroupLayout.PREFERRED_SIZE, 86, GroupLayout.PREFERRED_SIZE)
						.add(btnFiche, GroupLayout.PREFERRED_SIZE, 86, GroupLayout.PREFERRED_SIZE))
					.addContainerGap(24, Short.MAX_VALUE))
		);
		setLayout(groupLayout);
		createContents();
	}

	/**
	 * Create contents of the shell.
	 */
	protected void createContents()
	{
		setText("Configuration");
		setBackground(ApiController.bgColor);
		setSize(551, 161);

	}

	@Override
	protected void checkSubclass()
	{
		// Disable the check that prevents subclassing of SWT components
	}

}
